package com.rybbaby.tss.front.tssPayment.service.imp;

import com.rybbaby.tss.core.web.service.imp.BaseServiceImp;
import com.rybbaby.tss.front.tssPayment.dao.IViewPaymentDetailsDao;
import com.rybbaby.tss.front.tssPayment.entity.ViewPaymentDetails;
import com.rybbaby.tss.front.tssPayment.service.IViewPaymentDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 雷春琼
 * @description 缴费表数据库操作服务实现
 * @createDate 2017-08-10 上午12:22:55
 */
@Service
@Transactional
public class ViewPaymentDetailsServiceImp extends BaseServiceImp<ViewPaymentDetails> implements IViewPaymentDetailsService {

    @Autowired
    private IViewPaymentDetailsDao IViewPaymentDetailsDao;

    @Override
    public List<ViewPaymentDetails> packageDetailsList(String stuId) throws Exception {
        return IViewPaymentDetailsDao.packageDetailsList(stuId);
    }

    @Override
    public List<ViewPaymentDetails> otherPaymentDetailsList(String stuId) throws Exception {
        return IViewPaymentDetailsDao.otherPaymentDetailsList(stuId);
    }

    @Override
    public List<ViewPaymentDetails> DepositDetailsList(String stuId) throws Exception {
        return IViewPaymentDetailsDao.DepositDetailsList(stuId);
    }

    @Override
    public List<ViewPaymentDetails> packagePaymentDetails(String packageId) throws Exception {
        return IViewPaymentDetailsDao.packagePaymentDetails(packageId);
    }

    @Override
    public Map<String, Object> getPaymentListByMemberId(ViewPaymentDetails entity) throws Exception {
        Map<String, Object> map = new HashMap<>();
        //课时包详情列表
        List<ViewPaymentDetails> packageDetailsList = this.IViewPaymentDetailsDao.packageDetailsList(entity.getStuId());
        //课时包详情列表
        List<ViewPaymentDetails> DepositDetailsList = this.IViewPaymentDetailsDao.DepositDetailsList(entity.getStuId());
        //其它缴费列表
        List<ViewPaymentDetails> otherPaymentDetailsList = this.IViewPaymentDetailsDao.otherPaymentDetailsList(entity.getStuId());
        int index = 0;
        for (int j = 0; j < packageDetailsList.size(); j++) {
            ViewPaymentDetails paymentDetails = packageDetailsList.get(j);
            if (paymentDetails.getPaymentType() == 3) {
                List<ViewPaymentDetails> packagePaymentDetailsList = this.IViewPaymentDetailsDao.packagePaymentDetails(paymentDetails.getPackageId());
                paymentDetails.setPackageDetailsList(packagePaymentDetailsList);
            }
            index++;
            paymentDetails.setIndex(index);
        }
        for (int j = 0; j < DepositDetailsList.size(); j++) {
            ViewPaymentDetails paymentDetails = DepositDetailsList.get(j);
            index++;
            paymentDetails.setIndex(index);
        }
        for (int j = 0; j < otherPaymentDetailsList.size(); j++) {
            ViewPaymentDetails paymentDetails = otherPaymentDetailsList.get(j);
            index++;
            paymentDetails.setIndex(index);
        }

        map.put("packageDetailsList", packageDetailsList);
        map.put("DepositDetailsList", DepositDetailsList);
        map.put("otherPaymentDetailsList", otherPaymentDetailsList);
        return map;
    }

    @Override
    public ViewPaymentDetails packageRefundDetails(String packageId) throws Exception{
        List<ViewPaymentDetails> viewPaymentDetails = IViewPaymentDetailsDao.packageRefundDetails(packageId);
        return viewPaymentDetails.get(0);
    }

    @Override
    public ViewPaymentDetails depositRefundDetails(String paymentId) throws Exception {
        List<ViewPaymentDetails> viewPaymentDetails = IViewPaymentDetailsDao.depositRefundDetails(paymentId);
        return viewPaymentDetails.get(0);
    }

    @Override
    public Map<String,Object> OtherRefundDetails(String stuId, int paymentType) throws Exception{
        Map<String,Object> map = IViewPaymentDetailsDao.OtherRefundDetails(stuId,paymentType);
        return map;
    }
    public List<ViewPaymentDetails> getAllList() {
        return IViewPaymentDetailsDao.getAllList();
    }

    @Override
    public List<ViewPaymentDetails> findListByIds(List<String> ids) {
        return IViewPaymentDetailsDao.findListByIds(ids);
    }
}


